package com.ai.boot.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Li9527.
 * @Description
 * @create 2025/6/21 下午5:31
 */

@RestController
@RequestMapping("/api/ds")
public class ChatController {

    //依赖注入
    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    //实现简单对话功能
    @GetMapping("/chat")
    public String chat(@RequestParam(value = "message", defaultValue = "你是谁") String message) {
        return chatClient.prompt()  //提示词
                .user(message)   //用户输入的信息
                .call()   //请求大模型
                .content();   //返回结果
    }

}
